package com.leet.string;

import java.util.HashMap;
import java.util.Map;

public class IsTongGou {
    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> visited = new HashMap<>();
        if(s.length()!=t.length()){
            return false;
        }
        for(int i = 0 ; i < s.length();i++){
            if(!visited.containsKey(s.charAt(i))){
                visited.put(s.charAt(i),t.charAt(i));
                visited.put(t.charAt(i),s.charAt(i));
            }else if(visited.containsKey(s.charAt(i))){
                if(visited.get(s.charAt(i))!=t.charAt(i)){
                    return false;
                }
            }
        }
        return true;
    }
}
